#include"httplib.h"
#include"search.hpp"
#include"Log.hpp"
const std::string root_path="./wwwroot";
const std::string src_output="./data/raw_html";

int main()
{
    using namespace Log_Module;
    ns_search::Search search;
    search.InitSearch(src_output);
    
    httplib::Server svr;
    svr.set_base_dir(root_path.c_str());
    svr.Get("/s",[&search](const httplib::Request&req, httplib::Response& res){
        if(!req.has_param("word"))
        {
            res.set_content("缺少搜索关键词!", "text/plain; charset=utf-8");
            return;
        }
        //对word进行查找
        std::string answer; 
        LOG(Log_Level::INFO)<<"用户要查找的关键词是"<<answer;
        search.Search_string(req.get_param_value("Word"),&answer);
        //返回结果
        res.set_content(answer,"application/json");
    });
    LOG(Log_Level::INFO)<<"服务器启动成功...";
    svr.listen("0.0.0.0",8081);
    return 0;
}